package com.chelun.support.clmutifragment;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import com.chelun.support.clmutifragment.delegates.CatAdapterDelegate;
import com.chelun.support.clmutifragment.delegates.DogAdapterDelegate;
import com.chelun.support.clmutifragment.delegates.GeckoAdapterDelegate;
import com.chelun.support.clmutifragment.delegates.ImageAdapterDelegates;
import com.chelun.support.clmutifragment.delegates.SnakeAdapterDelegate;
import com.chelun.support.clmutifragment.model.ImageBean;
import com.chelun.support.clmutiplyfragment.MultiFunctionFragment;
import com.chelun.support.clmutiplyfragment.model.ListItemBean;
import com.hannesdorfmann.adapterdelegates3.AdapterDelegatesManager;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leo on 16/7/20.
 */
public class SampleFragment extends MultiFunctionFragment {
    private List<ListItemBean> mList;

    private int mAddNum = 3;
    private Handler mHandler = new Handler(Looper.getMainLooper());

    @Override
    public void onInit(Bundle savedInstanceState) {
        initViews();
    }

    private void initViews() {
        mList = new ArrayList<>();
//        getTopView().addView(LayoutInflater.from(getActivity()).inflate(R.layout.item_top,null));
        loadData();
        setHasLoadMore(true);
    }

    @Override
    public void onLoadMore() {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
//                Cat cat = new Cat("这是加载更多");
//                mList.add(cat);
//                mList.clear();
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201311%2F13%2F20131113151418_vr2kH.jpeg&thumburl=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2243750766%2C1873550089%26fm%3D21%26gp%3D0.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fwww.wallcoo.com%2Fflower%2FAmazing_Color_Flowers_2560x1600_IV%2Fwallpapers%2F2560x1600%2FFlowers_Wallpapers_169.jpg&thumburl=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D4153495698%2C3310312454%26fm%3D21%26gp%3D0.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Ftupian.enterdesk.com%2F2012%2F0602%2Fyt%2F19%2FFlowers_Wallpapers_109.jpg&thumburl=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D4009173256%2C1157715814%26fm%3D21%26gp%3D0.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fa08b87d6277f9e2f77818d081d30e924b899f37e.jpg&thumburl=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D495213cd5066d01661199928a72ad498%2Fa08b87d6277f9e2f77818d081d30e924b899f37e.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F18d8bc3eb13533fa997c342eaad3fd1f40345be3.jpg&thumburl=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D2a5a59df74094b36c4921ced93cd7c00%2F18d8bc3eb13533fa997c342eaad3fd1f40345be3.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fbd3eb13533fa828b8ac32afeff1f4134960a5ace.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3De732f4244936acaf46e091fc4cd88d03%2Fbd3eb13533fa828b8ac32afeff1f4134960a5ace.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Ff11f3a292df5e0fe8429ca47596034a85edf7246.jpg&thumburl=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dab0c4c853f87e9505d17f46c2038531b%2Ff11f3a292df5e0fe8429ca47596034a85edf7246.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F0eb30f2442a7d9338e2370bcaf4bd11372f00171.jpg&thumburl=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D5f6e1dc1b33533faeab6942e98d1fdca%2F0eb30f2442a7d9338e2370bcaf4bd11372f00171.jpg"));
                mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dd0eda80b59b5c9ea7df304e3e538b622%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg"));
                loadMoreComplete();
                setItem(mList);
            }
        }, 800);
    }

    private void loadData() {
//        Cat cat = new Cat("这是猫");
//        Dog dog = new Dog("这个是狗");
//        Snake snake = new Snake("这个是蛇","");
//        for (int i = 0; i < mAddNum; i++) {
//            mList.add(cat);
//            mList.add(dog);
//            mList.add(snake);
//        }

        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201311%2F13%2F20131113151418_vr2kH.jpeg&thumburl=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2243750766%2C1873550089%26fm%3D21%26gp%3D0.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fwww.wallcoo.com%2Fflower%2FAmazing_Color_Flowers_2560x1600_IV%2Fwallpapers%2F2560x1600%2FFlowers_Wallpapers_169.jpg&thumburl=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D4153495698%2C3310312454%26fm%3D21%26gp%3D0.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Ftupian.enterdesk.com%2F2012%2F0602%2Fyt%2F19%2FFlowers_Wallpapers_109.jpg&thumburl=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D4009173256%2C1157715814%26fm%3D21%26gp%3D0.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fa08b87d6277f9e2f77818d081d30e924b899f37e.jpg&thumburl=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D495213cd5066d01661199928a72ad498%2Fa08b87d6277f9e2f77818d081d30e924b899f37e.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F18d8bc3eb13533fa997c342eaad3fd1f40345be3.jpg&thumburl=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D2a5a59df74094b36c4921ced93cd7c00%2F18d8bc3eb13533fa997c342eaad3fd1f40345be3.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fbd3eb13533fa828b8ac32afeff1f4134960a5ace.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3De732f4244936acaf46e091fc4cd88d03%2Fbd3eb13533fa828b8ac32afeff1f4134960a5ace.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Ff11f3a292df5e0fe8429ca47596034a85edf7246.jpg&thumburl=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dab0c4c853f87e9505d17f46c2038531b%2Ff11f3a292df5e0fe8429ca47596034a85edf7246.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F0eb30f2442a7d9338e2370bcaf4bd11372f00171.jpg&thumburl=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D5f6e1dc1b33533faeab6942e98d1fdca%2F0eb30f2442a7d9338e2370bcaf4bd11372f00171.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dd0eda80b59b5c9ea7df304e3e538b622%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg"));

        setItem(mList);
    }

    @Override
    public void onRefresh() {
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dd0eda80b59b5c9ea7df304e3e538b622%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201311%2F13%2F20131113151418_vr2kH.jpeg&thumburl=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2243750766%2C1873550089%26fm%3D21%26gp%3D0.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fwww.wallcoo.com%2Fflower%2FAmazing_Color_Flowers_2560x1600_IV%2Fwallpapers%2F2560x1600%2FFlowers_Wallpapers_169.jpg&thumburl=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D4153495698%2C3310312454%26fm%3D21%26gp%3D0.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Ftupian.enterdesk.com%2F2012%2F0602%2Fyt%2F19%2FFlowers_Wallpapers_109.jpg&thumburl=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D4009173256%2C1157715814%26fm%3D21%26gp%3D0.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fa08b87d6277f9e2f77818d081d30e924b899f37e.jpg&thumburl=http%3A%2F%2Fa.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D495213cd5066d01661199928a72ad498%2Fa08b87d6277f9e2f77818d081d30e924b899f37e.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F18d8bc3eb13533fa997c342eaad3fd1f40345be3.jpg&thumburl=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D2a5a59df74094b36c4921ced93cd7c00%2F18d8bc3eb13533fa997c342eaad3fd1f40345be3.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fbd3eb13533fa828b8ac32afeff1f4134960a5ace.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3De732f4244936acaf46e091fc4cd88d03%2Fbd3eb13533fa828b8ac32afeff1f4134960a5ace.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Ff11f3a292df5e0fe8429ca47596034a85edf7246.jpg&thumburl=http%3A%2F%2Ff.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dab0c4c853f87e9505d17f46c2038531b%2Ff11f3a292df5e0fe8429ca47596034a85edf7246.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F0eb30f2442a7d9338e2370bcaf4bd11372f00171.jpg&thumburl=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3D5f6e1dc1b33533faeab6942e98d1fdca%2F0eb30f2442a7d9338e2370bcaf4bd11372f00171.jpg"));
        mList.add(new ImageBean("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg&thumburl=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fh%253D200%2Fsign%3Dd0eda80b59b5c9ea7df304e3e538b622%2F9c16fdfaaf51f3de50f9276496eef01f3a297963.jpg"));

//        mList.add(0,new Cat("这个是刷新"));
        setItem(mList);
    }

    @Override
    public void onErrorLoadMore() {

    }

    @Override
    public void addAdapterDelegate(AdapterDelegatesManager<List<ListItemBean>> delegatesManager) {
        delegatesManager.addDelegate(new CatAdapterDelegate());
        delegatesManager.addDelegate(new DogAdapterDelegate());
        delegatesManager.addDelegate(new GeckoAdapterDelegate());
        delegatesManager.addDelegate(new SnakeAdapterDelegate());
        delegatesManager.addDelegate(new ImageAdapterDelegates());
    }


}
